home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 11 - 1995 / 11.02 Feb 95 / Yenta / Erics C++ Libraries / Interface Classes / CPPDRequest.cp < prev    next >
Encoding:
Text File  |  1996-04-04  |  3.9 KB  |  154 lines  |  [TEXT/KAHL]

  1. /***************************************************** IMPLEMENTATION
  2.     DATE:    10/5/93
  3.     AUTHOR: Eric R. Rosé
  4.  
  5.     CLASS:  CPPDRequest
  6.     
  7.     SUPERCLASS: CPPWindow
  8.     
  9.         This C++ class manages a general request window
  10.     
  11. ********************************************************************/
  12.  
  13. #include <CPPDRequest.h>
  14. #include <CPPWindowManager.h>
  15. #include <CPPButton.h>
  16. #include <CPPDialogText.h>
  17. #include <CPPStaticText.h>
  18. #include <ToolboxTools.h>
  19.  
  20. /*-----------------------------------------------------------------*/
  21. /*-------------------------- GLOBALS ------------------------------*/
  22. /*-----------------------------------------------------------------*/
  23.  
  24. Rect    DRequestBounds = {40, 40, 181, 368};
  25.  
  26. extern    CPPWindowManager    *gWindowManager;
  27. extern    void DoStdOKButton (CPPWindow *theWindow);
  28. extern    void DoStdCancelButton (CPPWindow *theWindow);
  29.  
  30. /*-----------------------------------------------------------------*/
  31. /*------------------------ PUBLIC METHODS -------------------------*/
  32. /*-----------------------------------------------------------------*/
  33.  
  34.     CPPDRequest::CPPDRequest (CPPWindowManager *theManager,
  35.                               StringPtr Prompt, StringPtr DefaultReply) : 
  36.                     CPPWindow (theManager, &DRequestBounds, "\pDRequest",
  37.                                TRUE, dBoxProc, FALSE, 13, TRUE, TRUE, 
  38.                                systemFont, 12)
  39.     {
  40.         Rect    tempRect;
  41.         CPPStaticText    *ST;
  42.         
  43.         SetRect (&tempRect, 8, 8, 299, 57);
  44.         ST = new CPPStaticText ((CPPWindow *)this, &tempRect, Prompt, 
  45.                                 systemFont, 12, teJustLeft);
  46.         
  47.         SetRect (&tempRect, 8, 66, 299, 100);
  48.         reply = new CPPDialogText ((CPPWindow *)this, &tempRect,
  49.                                       DefaultReply, 255, systemFont, 12);
  50.         
  51.         SetRect (&tempRect, 220, 113, 295, 133);
  52.         okButton = new CPPButton ((CPPWindow *)this,  &tempRect, "\pOK", 
  53.                                   TRUE, FALSE, FALSE, TRUE, TRUE);
  54.         okButton->SetDoClickProc (DoStdOKButton);
  55.  
  56.         SetRect (&tempRect, 8, 113, 83, 133);
  57.         cancelButton = new CPPButton ((CPPWindow *)this, &tempRect, "\pCancel", 
  58.                                       FALSE, FALSE, FALSE, TRUE, TRUE);
  59.         cancelButton->SetDoClickProc (DoStdCancelButton);
  60.  
  61.         MakeTarget (reply);
  62.  
  63.     }
  64.     
  65. /*-----------------------------------------------------------------*/
  66.  
  67.     CPPDRequest::~CPPDRequest ()
  68.     {
  69.         
  70.     }
  71.  
  72. /*-----------------------------------------------------------------*/
  73.  
  74.     char    *CPPDRequest::ClassName (void)
  75.     {
  76.         return "CPPDRequest";
  77.     }
  78.     
  79. /*-----------------------------------------------------------------*/
  80.  
  81.     StringPtr    CPPDRequest::GetDialogData (void)
  82.     /* return the text of the reply string */
  83.     {
  84.         if (reply)
  85.           return reply->GetAsString();
  86.         else
  87.           return NULL;
  88.     }
  89.  
  90. /*-----------------------------------------------------------------*/
  91.  
  92.     Boolean    CPPDRequest::DoUserKey (EventRecord *theEvent)
  93.     {
  94.         char theKey;
  95.  
  96.         theKey = theEvent->message & charCodeMask;
  97.         if (!(theEvent->modifiers & cmdKey))
  98.           {
  99.               switch (theKey) {
  100.                   case kTab :
  101.                       return TRUE;
  102.                       break;
  103.                   case kEscape :
  104.                     if (cancelButton)
  105.                       cancelButton->SimulateClick();
  106.                       return TRUE;
  107.                       break;
  108.                   case kEnter :    
  109.                   case kReturn :
  110.                       if (okButton)
  111.                         okButton->SimulateClick();
  112.                       return TRUE;
  113.                       break;
  114.                   default:
  115.                       return CPPWindow::DoUserKey (theEvent);
  116.                       break;
  117.             } // switch
  118.           }
  119.         else
  120.           {
  121.             if (theKey == '.')
  122.               {
  123.                 if (cancelButton)
  124.                   cancelButton->SimulateClick();
  125.                   return TRUE;
  126.               }
  127.             else
  128.               return CPPWindow::DoUserKey (theEvent);
  129.           }
  130.     }
  131.  
  132. /*-----------------------------------------------------------------*/
  133.     
  134.     Boolean    DoRequest (StringPtr Prompt, StringPtr Default, StringPtr *Reply)
  135.     {
  136.         CPPDRequest        *theWindow;
  137.         Boolean            theResult;
  138.         
  139.         theWindow = new CPPDRequest (gWindowManager, Prompt, Default);
  140.           
  141.         if (theWindow)
  142.           {
  143.               theWindow->DoModalWindow ();
  144.               if ((theResult = theWindow->modalResult))
  145.                 *Reply = theWindow->GetDialogData ();
  146.               delete theWindow;
  147.               return theResult;
  148.           }
  149.         else
  150.           {
  151.               ErrorAlert (MemError(), "\pCould not display the 'request' dialog");
  152.             return FALSE;
  153.           }
  154.     }